﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Dispose(true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            MessageBox.Show("转换成功");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.button2.Visible = false;
            this.button3.Visible = false;
            this.textBox1.Visible = false;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string name = textBox2.Text.ToString();
            string pwd = textBox3.Text.ToString();
            if (name == "admin" && pwd == "admin")
            {
                this.label1.Visible = false;
                this.label2.Visible = false;
                this.textBox2.Visible = false;
                this.textBox3.Visible = false;
                this.button4.Visible = false;
                this.button5.Visible = false;
                this.button2.Visible = true;
                this.button3.Visible = true;
                this.textBox1.Visible = true;
                MessageBox.Show("登录成功");
            }
            else
            {
                this.textBox1.Clear();
                this.textBox2.Clear();
                textBox1.Focus();
                MessageBox.Show("登录失败");
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (textBox1.WordWrap == true)
            {
                textBox1.WordWrap = false;
                button2.Text = "自动换行";
            }else{
                textBox1.WordWrap = true;
                button2.Text = "取消自动换行";
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            using (FileStream fs = new FileStream(@"C:\Users\Public\Desktop\text.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                string str = textBox1.Text.ToString();
                byte[] bs = System.Text.Encoding.Default.GetBytes(str);
                fs.Write(bs, 0, bs.Length);
            }
            MessageBox.Show("保存成功！");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form2 from2 = new Form2();
            from2.Show();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.Show();
        }
    }
}
